package com.chinatsp.onlineapp.ui.violation;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.Toast;

import com.chinatsp.onlineapp.R;
import com.chinatsp.onlineapp.base.BaseActivity;
import com.chinatsp.onlineapp.bean.CityList;
import com.chinatsp.onlineapp.presenter.GetHotCityDao;

/**
 * 选择城市
 */
public class SelectCityActivity extends BaseActivity implements
		View.OnClickListener {

	private static int VIOLATION_CODE = 1;
	private static int LIMIT_CODE = 2;
	private EditText edtText;
	private GridView gvList;
	private ImageView ivBack;
	private Button btnOk;
	private GetHotCityDao mGetHotCityDao;

	private String city = null;
	private CityListAdapter cityListAdapter;
	private List<CityList> cityLists;
	private String selectCity = "北京";
	private String selectCityId = "京";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_select_city);
		initView();
	}

	private void initView() {
		edtText = (EditText) findViewById(R.id.sv_text);
		gvList = (GridView) findViewById(R.id.gv_list);
		ivBack = (ImageView) findViewById(R.id.iv_back);
		btnOk = (Button) findViewById(R.id.btn_ok);

		cityLists = new ArrayList<CityList>();

		cityLists.add(new CityList("北京市", "京", true));
		cityLists.add(new CityList("天津市", "津", false));
		cityLists.add(new CityList("哈尔滨市", "黑", false));
		cityLists.add(new CityList("沈阳市", "辽", false));
		cityLists.add(new CityList("南京市", "沪", false));
		cityLists.add(new CityList("苏州市", "苏", false));
		cityLists.add(new CityList("杭州市", "浙", false));
		cityLists.add(new CityList("济南市", "鲁", false));
		cityLists.add(new CityList("郑州市", "豫", false));
		cityLists.add(new CityList("武汉市", "鄂", false));
		cityLists.add(new CityList("长沙市", "湘", false));
		cityLists.add(new CityList("广州市", "粤", false));
		cityLists.add(new CityList("深圳市", "深", false));
		cityLists.add(new CityList("重庆市", "渝", false));
		cityLists.add(new CityList("成都市", "川", false));
		cityLists.add(new CityList("西安市", "陕", false));

		cityListAdapter = new CityListAdapter(this, cityLists);
		gvList.setAdapter(cityListAdapter);

		mGetHotCityDao = new GetHotCityDao(this, this);
		mGetHotCityDao.getHotList();

		ivBack.setOnClickListener(this);
		btnOk.setOnClickListener(this);
			
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.iv_back:
			Log.e("back", "back");
			finish();
			break;
		case R.id.btn_ok:
			selectCity = cityListAdapter.selectCity;
			Log.e("btn_ok", "btn_ok");
			for (int i = 0; i <cityLists.size(); i++) {
				if (cityLists.get(i).getName().contains(selectCity)) {
					selectCityId  = cityLists.get(i).getId();
				}
			}
			Intent intent = getIntent();
			intent.putExtra("selectCityId", selectCityId );
			intent.putExtra("selectCity", selectCity);
			setResult(1,intent);
//			setResult(LIMIT_CODE,intent);
			
			finish();
			break;
		}
	}
	

}
